<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
        *闭包
        *封装
        */ 
    let Stu=function(){
        var name="小爱";
        return {
            getName:function(){
                return name;
            },
            setName:function(na){
                name=na;
            }
        };
    }

    //tom和jerry是两个独立空间
    let tom=Stu();
    let jerry=Stu();

    tom.setName("小爱同学");
    console.log(tom.getName());
    console.log(jerry.getName());

    // console.log("姓名"+stu.getName());//拿数据
    // stu.setName("小爱同学");//赋值
    // console.log("姓名"+stu.getName());

    
    </script>
</body>
</html>